package com.baichuan.conf;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @Auther: leo
 * @Date: 2020/04/8 10:27
 * @Description: 主要用于获取当前服务启动端口
 */
@Component
@Slf4j
public class WebServerConfig implements ApplicationListener<WebServerInitializedEvent> {
    @Getter
    private int serverPort;
    ;

    @Override
    public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
        this.serverPort = webServerInitializedEvent.getWebServer().getPort();
    }
}
